// useFormSubmit.js
import { ref } from 'vue';

export function useFormSubmit(submitCallback) {
  const form = ref(null);
  const errors = ref({});

  async function handleSubmit() {
    if (form.value.checkValidity()) {
      try {
        await submitCallback();
      } catch (e) {
        // 处理错误
      }
    } else {
      // 表单验证失败
      form.value.classList.add('was-validated');
    }
  }

  return { form, errors, handleSubmit };
}
